<?php

namespace app\modules\Admin\service;

use app\modules\Admin\models\memberpickgoodslogModel;

class Memberpickgoodscardlog
{
    private static array $event = [
        'getcard',
        'pickgoods',
        'transfer',
        'refund',
        'recover',
    ];

    private static array $oper_type = [
        'admin',
        'system',
        'user',
    ];

    /**
     * @param array $logInfo ['member_pickgoods_card_id'=> 0, 'event', ....]
     * @return bool
     */
    public static function addLog(array $logInfo):bool
    {
        $newLogInfo = [];
        if(empty($logInfo['member_pickgoods_card_id'])){
            return false;
        }
        if(empty($logInfo['event']) || !in_array($logInfo['event'], self::$event)){
            return false;
        }
        if(empty($logInfo['oper_type']) || !in_array($logInfo['oper_type'], self::$oper_type)){
            return false;
        }
        $newLogInfo['member_pickgoods_card_id'] = $logInfo['member_pickgoods_card_id'];
        $newLogInfo['event'] = $logInfo['event'];
        $newLogInfo['event_id'] = $logInfo['event_id']??0;
        $newLogInfo['before'] = $logInfo['before']??0;
        $newLogInfo['money'] = $logInfo['money']??0;
        $newLogInfo['after'] = $logInfo['after']??0;
        $newLogInfo['remark'] = $logInfo['remark']??'无';
        $newLogInfo['oper_type'] = $logInfo['oper_type'];
        $newLogInfo['oper_id'] = $logInfo['oper_id']??0;
        $newLogInfo['created_at'] = timestamp();
        return memberpickgoodslogModel::query()->insert($newLogInfo);
    }
}